#include "Plan.h"

using namespace std;

Plan::Plan(const Point &p, const Vector &_v1)
{
	point=p; normal=_v1; normal.normalize();
}

Vector Plan::getNormal (const Point &p) const
{
	Vector res = Vector(normal);
	res.normalize();
	return res;
}

bool Plan::intersection(Ray& ray, Intersection& i) const
{
	double scalar = normal.scalar(ray.getDirection());
	if(scalar!=0)
	{	
		double dist = ( (normal*point- normal*ray.getOrigin() )/scalar );
		if (dist > 0.001) {
			i.setC(color);
			Vector v = Vector(normal);
			v.normalize();
			i.setNormal(v);
			i.setP((ray.getDirection() * dist) + ray.getOrigin());
			i.setDistance(dist);
			
			return(true);
		}
	}
	return(false);
}
